// pages/biz/orderDetail/orderDetail.js
// 订单列表、订单详情接口：status字段
// 1.显示活动未开始标签
// 2.显示待支付标签、显示支付按钮
// 3.显示活动进行中标签、显示立即秒杀按钮
// 4.显示已支付标签
// 5.显示支付超时标签
// 6.显示待退款标签
// 7.显示已退款标签
import Serv from './orderDetailServ';
var regeneratorRuntime = require("../../../../lib/js/runtime-module.js")
import Util from '../../../../utils/util2.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 1、活动未开始 2、活动进行中  3、待支付 4、已支付 5、支付超时 6、待退款 7、已退款
    status:0,
    statusMap:{
      1:{
        statusName:'活动未开始',
        statusTagColor:'tag_blue',//
        buttonName:'联系客服',
        buttonStype:'',
        showTime: true
      },
      2: {
        statusName: '待支付',
        statusTagColor: 'tag_yellow',//
        buttonName: '立即支付',
        buttonStype: 'bg_blue',
      },
      3:{
        statusName:'活动进行中',//状态名称
        statusTagColor: 'tag_yellow',// tag_yellow , tag_grey , tag_pink, tag_blue
        buttonName:'立即秒杀',//底部按钮，默认为‘联系客服’
        buttonStype:'bg_blue',//按钮样式，默认为白底篮筐，border_blue
        showTime:true
      },
      4:{
        statusName:'已支付',
        statusTagColor:'tag_blue',//
        buttonName:'联系销售',
        buttonStype:'',
      },
      5:{
        statusName:'支付超时',
        statusTagColor:'tag_grey',//
        buttonName:'',
        buttonStype:'',
      },
      6:{
        statusName:'待退款',
        statusTagColor:'tag_pink',//
        buttonName:'',
        buttonStype:'',
      },
      7:{
        statusName:'已退款',
        statusTagColor:'tag_grey',//
        buttonName:'',
        buttonStype:'',
      },
      8: {
        statusName: '活动已结束',
        statusTagColor: 'tag_grey',
        //buttonName:'联系客服',
        buttonStype: ''
      }
    },
    activityStatus:0,
    productDeType: [4, 5, 6, 7],
    productHouseType: [1, 2, 3]
  },

  getOrderDetial: async function (id){
    let { data, success, msg } = await Serv.queryOrderDetail(id)
    if (success){
      let endTime = Util.dateFromString(data.payTimeOut).getTime()
      this.setData({ endTime })
      if (data.startTime && data.endTime){
        let startTime = data.startTime.substr(0, data.startTime.length - 3),
          endTime = data.endTime.substr(0, data.endTime.length - 3)
        data.startTime = startTime
        data.endTime = endTime
      }
      // if(data.tags){
      //   console.log(data.tags)
      //   data.tags = data.tags.split(',')
      // }
      if (data.tags && data.tags.length >=3){
        data.tags.splice(3, data.tags.length-1)
      }
      data.cardNo = data.cardNo&&data.cardNo.replace(/^(.{4})(?:\d+)(.{4})$/, "$1******$2")
      this.setData({ detail: data,status:data.status})
    }else{
      console.log(msg)
    }
  },

  toNext(){
  
    let { status, seckillOrderId, seckillProductId,type} = this.data.detail
    if (status == 1 || status == 5 || status == 6 || status == 7){
      if (this.data.detail.estatePhone){
        wx.makePhoneCall({ phoneNumber: this.data.detail.estatePhone })
      }else{
        wx.showToast({
          title: '暂无客服联系方式',
          icon:'none'
        })
      }
    } else if (status == 3){
      wx.navigateTo({
        url: `/subPackages2/pages/kill/rushPurchase/rushPurchase?actionType=1&seckillProductId=${seckillProductId}`
      })
    } else if (status == 2){
      //debugger
      if(type==1){
        wx.navigateTo({
          url: `/subPackages2/pages/pay/payment/payment?seckillProductId=${seckillProductId}&actionType=1`
        })
      }else{
        wx.navigateTo({
          url: `/subPackages2/pages/pay/payment/payment?seckillOrderId=${seckillOrderId}&seckillProductId=${seckillProductId}&actionType=2`
        })
      }
      
    } else if (status == 4){
      wx.makePhoneCall({ phoneNumber: this.data.detail.consultantMobile })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({ orderId: options.id,tabIndex:options.tabIndex})
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getOrderDetial(this.data.orderId)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    clearTimeout(this.data.timeOut)
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    clearTimeout(this.data.timeOut)
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  filterStatus: function (statusList,curStatus) {
    return statusList.indexOf(Number(curStatus))
  },
})
